home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today (BR) Volume 2 #6 / CDRTV2N6.iso / makers / search.dir / 00075_Script_Bsearch script < prev    next >
Text File  |  1996-03-11  |  750b  |  34 lines

  1. on Bsearch str, txt
  2.   
  3.   set txt = the number of cast txt
  4.   set start = 1
  5.   set end = the number of lines of field txt  
  6.   set middle = (start + end) / 2  
  7.   put value(str) into str
  8.   put str
  9.   repeat while str <> value(item 1 of line middle of field txt)
  10.     
  11.     if str = value(item 1 of line end of field txt) then
  12.       return end
  13.     end if
  14.     
  15.     if start = middle then
  16.       return 0
  17.     end if 
  18.     
  19.     if str < value(item 1 of line middle of field txt) then
  20.       set end = middle
  21.     else
  22.       set start = middle
  23.     end if
  24.     set middle = (start + end) / 2  
  25.     
  26.   end repeat
  27.   
  28.   if str = value(item 1 of line middle of field txt) then
  29.     return middle
  30.   else
  31.     return 0
  32.   end if
  33.   
  34. end Bsearch